﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DLTN.Entities;
using DLTN.Data;
using System.Data;

public partial class Controls_ControlChuyenMucXemNhieuRight : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HienThiTinXemNhieu();
        }
    }

    private void HienThiTinXemNhieu()
    {
        int TotalRows = 0;
        string strHTML = "";
        string WhereClause = "1=1 ";
        

        TList<ChuyenMuc> TList_ChuyenMuc = DataRepository.ChuyenMucProvider.GetPaged(WhereClause, "LuotXem Desc", 0, 5, out TotalRows);
        
        if (TList_ChuyenMuc.Count > 0)
        {
            for (int i = 0; i < TList_ChuyenMuc.Count; i++)
            {
                strHTML += "<div class='tinxemnhieu'>";

                strHTML += (TList_ChuyenMuc[i].AnhDaiDien.ToString() == "no_image.jpg" ? "<img src='../../../" + "Images/no_image.jpg' class='img-left'/>" : "<img src='../../../Upload/ChuyenMuc/" + TList_ChuyenMuc[i].AnhDaiDien + "' class='img-left'/>");

                strHTML += "<a href='../../../" + "ChuyenMuc/" + TList_ChuyenMuc[i].Id + "/" + TList_ChuyenMuc[i].IdSubChuyenMuc + "/" + GetTieuDe(TList_ChuyenMuc[i].TieuDe) + ".aspx'>";

                strHTML += TList_ChuyenMuc[i].TieuDe + "</a>";
                strHTML += " " + formatString(TList_ChuyenMuc[i].TomTat, 140);

                if (i != TList_ChuyenMuc.Count - 1)
                {
                    strHTML += "<div class='news-line'></div>";
                }

                strHTML += "</div>";
            }
            ltrTinXemNhieu.Text = strHTML;
        }

        
    }

    public string formatString(string str, int n)
    {
        string kq = "";

        if (str.Length > n)
            kq = str.Substring(0, n + 1) + "...";
        else
            kq = str;

        return kq;
    }

    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }

    public string ChuanHoaChuoi(string chuoi, int n)
    {
        string kq = "";
        if (chuoi.Length > n)
            kq = chuoi.Substring(0, n);
        kq += "...";
        return kq;
    }
}